/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.apiGenerator.dataType.entityAllInterface;

import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.InterfaceGenerator;
import com.inspur.edp.caf.generator.item.InterfaceGeneratorContext;
import com.inspur.edp.cef.api.dataType.base.ICefDataType;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.apiGenerator.CefApiGeneratorContext;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public abstract class DataTypeAllInterfaceGenerator extends InterfaceGenerator {
  private CefApiGeneratorContext apiGenContext;
  private IGspCommonDataType dataType;

  protected DataTypeAllInterfaceGenerator(
      CefApiGeneratorContext apiGenContext, IGspCommonDataType dataType) {
    super(apiGenContext.getCompilationUnitInfo());
    this.apiGenContext = apiGenContext;
    this.dataType = dataType;
  }

  @Override
  protected final InterfaceGeneratorContext createInterfaceItemContext() {
    return createInterfaceGenContext();
  }

  @Override
  protected void beforeInitialize() {
    super.beforeInitialize();
    getContext()
        .getApiGenContext()
        .getEntityAllInterfaceTypes()
        .put(dataType.getCode(), new MediateType(apiGenContext.getPackageName(), getName()));
  }


  // keyword:
  // ORIGINAL LINE: protected new DataTypeAllInterfaceGenCtx getContext() { return
  // (DataTypeAllInterfaceGenCtx)super.getContext(); }
  @Override
  protected DataTypeAllInterfaceGenCtx getContext() {
    return (DataTypeAllInterfaceGenCtx) super.getContext();
  }

  protected DataTypeAllInterfaceGenCtx createInterfaceGenContext() {
    return new DataTypeAllInterfaceGenCtx(apiGenContext, dataType);
  }

  @Override
  protected ArrayList<TypeInfo> addParentInterfaces() {
    MediateType generated =
        getContext().getApiGenContext().getEntityInterfaceTypes().get(dataType.getCode());
//    if (generated == null) {
//      return new ArrayList<>();
//    }
    TypeInfo generatedEntityInterface = new TypeInfo(generated.getClassName());
    generatedEntityInterface.setTypePackageName(generated.getNamespace());

    return new java.util.ArrayList(
        java.util.Arrays.asList(
            new TypeInfo[] {getDefaultInterfaceType(), generatedEntityInterface}));
  }

  protected TypeInfo getDefaultInterfaceType() {
    return new TypeInfo(ICefDataType.class);
  }

  @Override
  protected java.util.ArrayList<ModifierKeyword> getAccessModifier() {
    return new java.util.ArrayList<ModifierKeyword>(
        java.util.Arrays.asList(new ModifierKeyword[] {ModifierKeyword.PUBLIC_KEYWORD}));
  }
}
